<?php
function baseUrl()
{
	$baseUrl = str_replace ( '\\', '/', dirname ( $_SERVER ['SCRIPT_NAME'] ) );
	$baseUrl = trim ( $baseUrl, '/' );
	$server = $_SERVER ['SERVER_NAME'] ? $_SERVER ['SERVER_NAME'] : $_SERVER ['REMOTE_ADDR'];
	$server .= ($_SERVER ['SERVER_PORT'] == "80") ? '' : ':' . $_SERVER ['SERVER_PORT'];
	return empty ( $baseUrl ) ? 'http://' . $server . '/' : 'http://' . $server . "/$baseUrl/";
}

function siteUrl($url = '')
{
	$urlPath = '';
	if (empty ( $url ))
	{
		$urlPath = baseUrl ();
	} else
	{
		if (URL_MODE == 0)
		{
			$urlPath = baseUrl () . $url;
		} else
		{
			if (URL_MODE == 1)
			{
				$urlPath = baseUrl () . APP_CONTROL.'/' . $url;
			} else
			{
				$urlPath = baseUrl () .APP_CONTROL. '?p=' . $url;
			}
		}
	}
	return $urlPath;
}
